import 'package:flutter/material.dart';
import 'package:flutter_picker_plus/picker.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:gameplay_flutter/lib_basemodel/user/user.dart';
import 'package:gameplay_flutter/lib_runtime/extension/string_extension/string_text.dart';
import 'package:gameplay_flutter/lib_runtime/extension/widget/widget_wrapper.dart';
import 'package:provider/provider.dart';

import '../../lib_baseview/theme/jr.dart';
import '../../lib_baseview/widget/appbar/custom_app_bar.dart';
import '../../m_main/debug/debug_page.dart';
import '../../resource/language/generated/l10n.dart';
import 'information_model.dart';

class InformationPage extends StatefulWidget {
  /// 用户模型
  final User? user;

  //   /// 手机号
  // final String phoneNum;

  // /// 区号
  // final String areaCode;
  const InformationPage({super.key, this.user});

  @override
  State<InformationPage> createState() => _InformationPageState();
}

class _InformationPageState extends State<InformationPage> {
  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return MultiProvider(
      providers: [
        ChangeNotifierProvider(create: (_) => InformationModel(widget.user)),
      ],
      child: Container(
        color: Colors.white,
        child: Stack(
          children: [
            Container(
              width: ScreenUtil().screenWidth,
              height: ScreenUtil().screenHeight,
              color: const Color(0xFF8A72FE),
            ),
            Scaffold(
              resizeToAvoidBottomInset: false,
              backgroundColor: Colors.transparent,
              appBar: CustomAppBar(
                backIconStr: 'common/common_white_icon.png',
                titleBuilder: (c) => T.current.login_edit_complete_date.text(
                  color: Colors.white,
                  fontSize: 20,
                  weight: TextFontWeight.bold,
                ),
              ),
              body: contentWidget(context).center(),
            )
          ],
        ),
      ).onTap(() {
        // print("cdddddd");

        // _ctrl.focusNode.
        FocusScope.of(context).unfocus();
      }),
    );
  }

  Widget contentWidget(BuildContext content) {
    return Consumer<InformationModel>(builder: (context, model, _) {
      return Column(
        children: [
          const SizedBox(height: 60),
          Stack(
            children: [
              SizedBox(
                width: 90,
                height: 90,
                // color: Colors.red,
                child: model.userInfo?.headPortraitsUrl != null
                    ? JR.img('${model.userInfo!.headPortraitsUrl}')
                    : const SizedBox.shrink(),
              ).corner(radius: 90 / 2.0),
              JR
                  .img('login/info/info_camera.png', width: 44, height: 44)
                  .positioned(end: 0, bottom: 0),
            ],
          ),
          SizedBox(
            width: ScreenUtil().screenWidth - 80,
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                T.current.login_edit_name_taken
                    .text(color: const Color(0xFFCEC3FF), fontSize: 12)
                    .padding(top: 18)
                    .padding(start: 14),
                Container(
                  color: const Color(0xFFFFFFFF),
                  height: 43,
                  child: Stack(
                    children: [
                      (model.userInfo?.nickname ?? '')
                          .text(color: const Color(0xFF1B1B1B), fontSize: 14)
                          .colorBg(bgColor: Colors.transparent),
                      JR
                          .img('login/info/info_change_name.png',
                              height: 18, width: 18)
                          // .padding(end: 19)
                          .onTap(() {
                        model.fetchUpdataName();
                      }).positioned(end: 19, top: (43 - 18) / 2.0),
                    ],
                  ),
                ).corner(radius: 43 / 2.0).padding(top: 8),
                T.current.login_edit_choose_gender
                    .text(color: const Color(0xFFCEC3FF), fontSize: 12)
                    .padding(start: 14, top: 16),
                Container(
                  color: const Color(0xFFFFFFFF),
                  height: 43,
                  child: Row(
                    children: [
                      Expanded(
                        child: Container(
                          color: model.boySelect
                              ? const Color(0xFFFFFFFF)
                              : Color(0xFF9D89FF),
                          height: 43,
                          child: Row(
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                            children: [
                              T.current.login_edit_boy
                                  .text(
                                      color: model.boySelect
                                          ? const Color(0xFF1B1B1B)
                                          : const Color(0xFFCFC5FF),
                                      fontSize: 14)
                                  .padding(start: 25),
                              JR
                                  .img('login/info/info_boy.png', height: 18)
                                  .padding(end: 18)
                            ],
                          ),
                        ).onTap(() {
                          model.setBoySelectStr(true);
                        }),
                      ),
                      Expanded(
                        child: Container(
                          color: model.boySelect
                              ? const Color(0xFF9D89FF)
                              : const Color(0xFFFFFFFF),
                          height: 43,
                          child: Row(
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                            children: [
                              T.current.login_edit_girl
                                  .text(
                                      // color: const Color(0xFFCFC5FF),
                                      color: model.boySelect
                                          ? const Color(0xFFCFC5FF)
                                          : const Color(0xFF1B1B1B),
// CFC5FF

                                      fontSize: 14)
                                  .padding(start: 25),
                              JR
                                  .img('login/info/info_girl.png', height: 18)
                                  .padding(end: 18)
                            ],
                          ),
                        ).onTap(() {
                          model.setBoySelectStr(false);
                        }),
                      ),
                    ],
                  ),
                ).corner(radius: 43 / 2.0).padding(top: 8),
                T.current.login_edit_brithday
                    .text(color: const Color(0xFFCEC3FF), fontSize: 12)
                    .padding(start: 14, top: 16),
                Container(
                  color: const Color(0xFFFFFFFF),
                  // width: 200,
                  height: 43,
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      '1988'
                          .text(color: const Color(0xFF1B1B1B), fontSize: 14)
                          .padding(start: 18),
                      // common_right_blue_icon.png
                      JR
                          .img('common/common_right_blue_icon.png', height: 30)
                          .padding(end: 10),
                    ],
                  ),
                ).corner(radius: 43 / 2.0).padding(top: 8).onTap(() {
                  showPickerDateTime(context);
                }),
                T.current.login_edit_country_selection
                    .text(color: Color(0xFFCEC3FF), fontSize: 12)
                    .padding(start: 14, top: 16),
                Container(
                  color: const Color(0xFFFFFFFF),
                  height: 43,
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      'My Country'
                          .text(color: Color(0xFF1B1B1B), fontSize: 14)
                          .padding(start: 18),
                      // common_right_blue_icon.png
                      Row(
                        children: [
                          Container(
                              color: Colors.yellow,
                              child: JR.img('common/common_right_blue_icon.png')
                              // .padding(end: 20),
                              ),
                          JR
                              .img('common/common_right_blue_icon.png',
                                  height: 30)
                              .padding(end: 10),
                        ],
                      ),
                    ],
                  ),
                ).corner(radius: 43 / 2.0).padding(top: 8),
              ],
            ),
          ),

          // go 按钮
          Container(
            width: 70,
            height: 70,
            color: const Color(0xFF000000).withAlpha((0.35 * 255).toInt()),
            child: T.current.login_edit_go
                .text(
                    color: Color(0xFFA89DE2),
                    fontSize: 26,
                    weight: TextFontWeight.medium)
                .center(),
          ).corner(radius: 35).onTap(() {
            print("go 按钮点击");
          }).padding(top: 50),
        ],
      );
    });
  }

  showPickerDateTime(BuildContext context) {
    Picker(
        height: 330,
        adapter: DateTimePickerAdapter(
          type: PickerDateTimeType.kYMD,
          isNumberMonth: true,
          // yearSuffix: "年",
          // monthSuffix: "月",
          // daySuffix: "日",
          // hourSuffix: "時",
          // minuteSuffix: "分",
          // secondSuffix: "秒",
          // minuteInterval: 30,
        ),
        title: Column(
          children: [
            // Text("Select DateTime"),
            T.current.login_edit_date_birth.text(
                color: Color(0xFF1B1B1B),
                fontSize: 18,
                weight: TextFontWeight.bold),
            // Text("Select DateTime"),
            SizedBox(
              width: ScreenUtil().screenWidth - 58 * 2,
              child: T.current.login_edit_birth_tips
                  .text(color: Color(0xFFA8A8A8), fontSize: 11),
            )
          ],
        ),
        // textAlign: TextAlign.right,
        delimiter: [
          // PickerDelimiter(
          //     column: 5,
          //     child: Container(
          //       width: 16.0,
          //       alignment: Alignment.center,
          //       child: Text(':', style: TextStyle(fontWeight: FontWeight.bold)),
          //     ))
        ],
        // footer: Container(
        //   height: 50.0,
        //   alignment: Alignment.center,
        //   child: Text('Footer'),
        // ),
        onConfirm: (Picker picker, List value) {
          print(picker.adapter.text);
        },
        onSelect: (Picker picker, int index, List<int> selected) {
          setState(() {
            print('${picker.adapter.toString()}');
            // stateText = picker.adapter.toString();
          });
        }).showBottomSheet(context);
  }

  @override
  void dispose() {
    super.dispose();
  }
}
